(function($) {

	$.fn.spinner = function(options) {
	
        var settings = $.extend({
            img         : 'https://jquery-spinner-plugin.googlecode.com/svn/spinner.gif',
            size        : 64
        }, options);
	
		this.each(function() {
			
			var _spinnerID = $(this).attr("id") + "-spinner";

			if(options !== false)
			{
				if ( $("#" + _spinnerID).length ) { 
					$("#" + _spinnerID).show();
					
					var offset = $(this).offset();
					offset.top+=(($(this).height())-settings.size)/2;
					offset.left+=(($(this).width())-settings.size)/2;
					
					$("#" + _spinnerID).css("top",offset.top);
					$("#" + _spinnerID).css("left",offset.left);
				}
				else {				
					var _zIndex = ($(this).attr("z-index") + 1);
					if(_zIndex){ _zIndex++; }
					else {
						_zIndex = 99999;
					}
					var offset = $(this).offset();
					offset.top+=(($(this).height())-settings.size)/2;
					offset.left+=(($(this).width())-settings.size)/2;
					
					this._spinner = $('<div id="' + _spinnerID + '" style="position:absolute; z-index:' + _zIndex + '; top:' + offset.top + 'px; left:' + offset.left + 'px;" ><img width="' + settings.size + '" src="' + settings.img + '" /></div>');

					var _spinner = $(this).append(this._spinner);
				}
			}
			else {
				if ( $("#" + _spinnerID).length ) {
					$("#" + _spinnerID).hide();
				}
			}
		});
		return this;
	};

})(jQuery);
